package com.qifenqian.turbot.module.presenter

import android.content.Context
import android.view.View

import com.qifenqian.turbot.base.BasePresenter
import com.qifenqian.turbot.module.contract.MarketingContract
import com.qifenqian.turbot.module.entity.response.marketing.*
import com.qifenqian.turbot.module.model.MarketingModel
import com.qifenqian.turbot.net.ModelCallback

/**
 * @author H
 * @createTime 2019/1/18 10:03
 * @description
 * @see
 * @since
 */
class MarketingPresenter(context: Context, view: MarketingContract.View) : BasePresenter<MarketingContract.View, MarketingModel>(context, view), MarketingContract.Presenter {

    override fun saveEarlyPayDiscount(request: EarlyPayDiscountEntity) {
        mModel.saveEarlyPayDiscount(request, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.saveEarlyPayDiscountResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.saveEarlyPayDiscountResult(false, code, msg)
            }
        })
    }

    override fun getEarlyPayDiscount() {
        mModel.getEarlyPayDiscount(object : ModelCallback<EarlyPayDiscountEntity> {
            override fun onSuccess(msg: String?, t: EarlyPayDiscountEntity?) {
                mView?.getEarlyPayDiscountResult(true, msg = msg, t = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getEarlyPayDiscountResult(false, code, msg)
            }
        })
    }

    override fun saveFullReduction(request: FullReductionEntity) {
        mModel.saveFullReduction(request, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.saveFullReductionResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.saveFullReductionResult(false, code, msg)
            }
        })
    }

    override fun getFullReduction() {
        mModel.getFullReduction(object : ModelCallback<FullReductionEntity> {
            override fun onSuccess(msg: String?, t: FullReductionEntity?) {
                mView?.getFullReductionResult(true, msg = msg, t = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getFullReductionResult(false, code, msg)
            }
        })
    }

    override fun saveShareDiscount(request: ShareDiscountEntity) {
        mModel.saveShareDiscount(request, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.saveShareDiscountResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.saveShareDiscountResult(false, code, msg)
            }
        })
    }

    override fun getShareDiscount() {
        mModel.getShareDiscount(object : ModelCallback<ShareDiscountEntity> {
            override fun onSuccess(msg: String?, t: ShareDiscountEntity?) {
                mView?.getShareDiscountResult(true, msg = msg, shareDiscountEntity = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getShareDiscountResult(false, code, msg)
            }
        })
    }

    override fun getDiscountDishes() {
        mModel.getDiscountDishes(object : ModelCallback<DiscountDishEntity> {
            override fun onSuccess(msg: String?, t: DiscountDishEntity?) {
                mView?.getDiscountDishesResult(true, msg = msg, discountDishEntity = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getDiscountDishesResult(false, code, msg)
            }
        })
    }

    override fun deleteFreeTimeDiscount(id: Int) {
        mModel.deleteFreeTimeDiscount(id, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.deleteFreeTimeDiscountResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.deleteFreeTimeDiscountResult(false, code, msg)
            }
        })
    }

    override fun saveFreeTimeDiscountDetail(request: FreeTimeDiscountDetailEntity) {
        mModel.saveFreeTimeDiscountDetail(request, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.saveFreeTimeDiscountDetailResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.saveFreeTimeDiscountDetailResult(false, code, msg)
            }
        })
    }

    override fun getFreeTimeDiscountDetail() {
        mModel.getFreeTimeDiscountDetail(object : ModelCallback<FreeTimeDiscountDetailEntity> {
            override fun onSuccess(msg: String?, t: FreeTimeDiscountDetailEntity?) {
                mView?.getFreeTimeDiscountDetailResult(true, msg = msg, t = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getFreeTimeDiscountDetailResult(false, code, msg)
            }
        })
    }

    override fun getFreeTimeDiscount() {
        mModel.getFreeTimeDiscount(object : ModelCallback<FreeTimeDiscountDetailEntity> {
            override fun onSuccess(msg: String?, t: FreeTimeDiscountDetailEntity?) {
                mView?.getFreeTimeDiscountResult(true, msg = msg, t = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getFreeTimeDiscountResult(false, code, msg)
            }
        })
    }

    override fun saveSpecialDishes(request: SpecialDishEntity) {
        mModel.saveSpecialDishes(request, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.saveSpecialDishesResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.saveSpecialDishesResult(false, code, msg)
            }
        })
    }

    override fun deleteSpecialDish(id: Int, view: View) {
        mModel.deleteSpecialDish(id, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.deleteSpecialDishResult(true, msg = msg, view = view)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.deleteSpecialDishResult(false, code, msg)
            }
        })
    }

    override fun getSpecialDishes() {
        mModel.getSpecialDishes(object : ModelCallback<SpecialDishEntity> {
            override fun onSuccess(msg: String?, t: SpecialDishEntity?) {
                mView?.getSpecialDishesResult(true, msg = msg, specialDishEntity = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getSpecialDishesResult(false, code, msg)
            }
        })
    }

    override fun getMarketingPage() {
        mModel.getMarketingPage(object : ModelCallback<MarketingHomeEntity> {
            override fun onSuccess(msg: String?, t: MarketingHomeEntity?) {
                mView?.getMarketingPageResult(true, msg = msg, marketingHomeEntity = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getMarketingPageResult(false, code, msg)
            }
        })
    }

    override fun createModel(): MarketingModel {
        return MarketingModel(mContext)
    }
}
